Skip to content

refactor: Enforce ServerCallContext in request handling#882

Merged
sokoliva merged 19 commits intoa2aproject:1.0-devfrom
sokoliva:Server-Call-Context-Mandatory
Mar 26, 2026
Merged

refactor: Enforce ServerCallContext in request handling#882
sokoliva merged 19 commits intoa2aproject:1.0-devfrom
sokoliva:Server-Call-Context-Mandatory

Conversation

@sokoliva
Copy link
Member

@sokoliva sokoliva commented Mar 20, 2026

Description

  • Make ServerCallContext a mandatory parameter across all TaskStore implementations (TaskStore interface, DatabaseTaskStore, and InMemoryTaskStore) and update tests.
  • Make ServerCallContext a mandatory parameter in RequestContext.

Previously, context defaulted to None, which could allow callers to bypass authorization scoping if the context was set to None. By requiring the context, we guarantee that the owner_resolver always has the necessary request context to determine scope boundaries.

Fixes #718 🦕

@sokoliva sokoliva requested a review from guglielmo-san March 20, 2026 16:57
@sokoliva sokoliva requested a review from a team as a code owner March 20, 2026 16:57
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the TaskStore operations to enforce the use of ServerCallContext as a mandatory parameter. This change significantly enhances the security posture by ensuring that all task-related operations are consistently performed within a defined authorization scope, preventing scenarios where context could be inadvertently omitted. The update promotes a more robust and predictable interaction with task storage mechanisms across the application.

Highlights

  • Mandatory ServerCallContext: The ServerCallContext parameter is now mandatory across all TaskStore operations, including the TaskStore interface, DatabaseTaskStore, and InMemoryTaskStore implementations. This change removes the possibility of None being passed as a context, ensuring proper authorization scoping.
  • Enhanced Security and Consistency: By requiring ServerCallContext, the system guarantees that the owner_resolver always has the necessary request context to determine scope boundaries, preventing potential bypasses of authorization scoping that could occur when the context defaulted to None.
  • Updated Owner Resolver: The OwnerResolver type definition and the resolve_user_scope function in owner_resolver.py have been updated to explicitly require ServerCallContext, removing the None option and the associated None check.
  • Comprehensive Test Updates: All relevant test cases in test_database_task_store.py, test_inmemory_task_store.py, and test_owner_resolver.py have been updated to reflect the mandatory ServerCallContext parameter, including the introduction of a TEST_CONTEXT constant for consistent testing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Mar 20, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/agent_execution/context.py 96.40% 97.22% 🟢 +0.83%
Total 91.47% 91.47% 🟢 +0.01%

Generated by coverage-comment.yml

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the TaskStore interface and its implementations (DatabaseTaskStore and InMemoryTaskStore) to enforce the use of ServerCallContext in all operations. This change ensures that the owner_resolver always has the necessary request context for determining scope boundaries, addressing a potential authorization bypass. The tests have also been updated to reflect this change.

@sokoliva sokoliva changed the title refactor: Enforce ServerCallContext in all TaskStore operations refactor: Enforce ServerCallContext in request handling Mar 26, 2026
@sokoliva sokoliva requested a review from ishymko March 26, 2026 11:09
@sokoliva
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the a2a server and task management components to enforce the mandatory presence of ServerCallContext in various async methods and class constructors. This change removes Optional type hints and associated None checks, simplifying the API and ensuring context availability across TaskStore implementations, RequestContext and TaskManager initialization, and OwnerResolver functions. Corresponding test files have been updated to reflect these changes, including the introduction of a TEST_CONTEXT for consistency. A review comment suggests improving the descriptiveness of a test function name and its docstring in tests/server/test_owner_resolver.py for enhanced code clarity.

@sokoliva sokoliva merged commit c367c83 into a2aproject:1.0-dev Mar 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants